const { By, until } = require('selenium-webdriver')

module.exports = function getDownloadCount (driver, appid) {
  return driver.get(`https://www.qimai.cn/app/downloadEstimate/appid/${appid}/country/cn`)
  .then(() => {
    return driver.wait(until.elementsLocated(By.css('.ivu-table-cell')))
  })
  .then(() => {
    return driver.sleep(3000)
  })
  .then(() => {
    return driver.findElement(By.css('.filter-content ul li:nth-of-type(4)')).click()
  })
  .then(() => {
    return driver.sleep(3000)
  })
  .then(() => {
    return driver.findElement(By.css('.download-num .date')).getText()
  })
  .then((count) => {
    return {
      count: count.match(/(\d+)$/)[1]
    }
  })
}